<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Stream Types</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Boost.Beast">
<link rel="up" href="../using_io.html" title="Using I/O">
<link rel="prev" href="asio_refresher.html" title="Asio Refresher">
<link rel="next" href="buffer_types.html" title="Buffer Types">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="asio_refresher.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../using_io.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="buffer_types.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="beast.using_io.stream_types"></a><a class="link" href="stream_types.html" title="Stream Types">Stream Types</a>
</h3></div></div></div>
<p>
        A <a class="link" href="../concepts/streams.html" title="Streams"><span class="bold"><strong>Stream</strong></span></a>
        is a communication channel where data is transferred as an ordered sequence
        of octet buffers. Streams are either synchronous or asynchronous, and may
        allow reading, writing, or both. Note that a particular type may model more
        than one concept. For example, the Asio types <a href="../../../../../../doc/html/boost_asio/reference/ip__tcp/socket.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">socket</span></code></a>
        and <a href="../../../../../../doc/html/boost_asio/reference/ssl__stream.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ssl</span><span class="special">::</span><span class="identifier">stream</span></code></a>
        support both <a class="link" href="../concepts/streams.html#beast.concepts.streams.SyncStream"><span class="bold"><strong>SyncStream</strong></span></a> and <a class="link" href="../concepts/streams.html#beast.concepts.streams.AsyncStream"><span class="bold"><strong>AsyncStream</strong></span></a>. All stream algorithms in Beast
        are declared as template functions using these concepts:
      </p>
<div class="table">
<a name="beast.using_io.stream_types.stream_concepts"></a><p class="title"><b>Table&#160;1.2.&#160;Stream Concepts</b></p>
<div class="table-contents"><table class="table" summary="Stream Concepts">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Concept
                </p>
              </th>
<th>
                <p>
                  Description
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  <a href="../../../../../../doc/html/boost_asio/reference/SyncReadStream.html" target="_top"><span class="bold"><strong>SyncReadStream</strong></span></a>
                </p>
              </td>
<td>
                <p>
                  Supports buffer-oriented blocking reads.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a href="../../../../../../doc/html/boost_asio/reference/SyncWriteStream.html" target="_top"><span class="bold"><strong>SyncWriteStream</strong></span></a>
                </p>
              </td>
<td>
                <p>
                  Supports buffer-oriented blocking writes.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../concepts/streams.html#beast.concepts.streams.SyncStream"><span class="bold"><strong>SyncStream</strong></span></a>
                </p>
              </td>
<td>
                <p>
                  A stream supporting buffer-oriented blocking reads and writes.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a href="../../../../../../doc/html/boost_asio/reference/AsyncReadStream.html" target="_top"><span class="bold"><strong>AsyncReadStream</strong></span></a>
                </p>
              </td>
<td>
                <p>
                  Supports buffer-oriented asynchronous reads.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a href="../../../../../../doc/html/boost_asio/reference/AsyncWriteStream.html" target="_top"><span class="bold"><strong>AsyncWriteStream</strong></span></a>
                </p>
              </td>
<td>
                <p>
                  Supports buffer-oriented asynchronous writes.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../concepts/streams.html#beast.concepts.streams.AsyncStream"><span class="bold"><strong>AsyncStream</strong></span></a>
                </p>
              </td>
<td>
                <p>
                  A stream supporting buffer-oriented asynchronous reads and writes.
                </p>
              </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
        These template metafunctions check whether a given type meets the requirements
        for the various stream concepts, and some additional useful utilities. The
        library uses these type checks internally and also provides them as public
        interfaces so users may use the same techniques to augment their own code.
        The use of these type checks helps provide more concise errors during compilation:
      </p>
<div class="table">
<a name="beast.using_io.stream_types.stream_type_checks"></a><p class="title"><b>Table&#160;1.3.&#160;Stream Type Checks</b></p>
<div class="table-contents"><table class="table" summary="Stream Type Checks">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Name
                </p>
              </th>
<th>
                <p>
                  Description
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__get_lowest_layer.html" title="get_lowest_layer"><code class="computeroutput"><span class="identifier">get_lowest_layer</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Returns <code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="identifier">lowest_layer_type</span></code> if it exists,
                  else returns <code class="computeroutput"><span class="identifier">T</span></code>.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__has_get_executor.html" title="has_get_executor"><code class="computeroutput"><span class="identifier">has_get_executor</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if the <code class="computeroutput"><span class="identifier">get_executor</span></code>
                  member function is present.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_async_read_stream.html" title="is_async_read_stream"><code class="computeroutput"><span class="identifier">is_async_read_stream</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of <a href="../../../../../../doc/html/boost_asio/reference/AsyncReadStream.html" target="_top"><span class="bold"><strong>AsyncReadStream</strong></span></a>.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_async_stream.html" title="is_async_stream"><code class="computeroutput"><span class="identifier">is_async_stream</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of both <a href="../../../../../../doc/html/boost_asio/reference/AsyncReadStream.html" target="_top"><span class="bold"><strong>AsyncReadStream</strong></span></a> and <a href="../../../../../../doc/html/boost_asio/reference/AsyncWriteStream.html" target="_top"><span class="bold"><strong>AsyncWriteStream</strong></span></a>.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_async_write_stream.html" title="is_async_write_stream"><code class="computeroutput"><span class="identifier">is_async_write_stream</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of <a href="../../../../../../doc/html/boost_asio/reference/AsyncWriteStream.html" target="_top"><span class="bold"><strong>AsyncWriteStream</strong></span></a>.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_completion_handler.html" title="is_completion_handler"><code class="computeroutput"><span class="identifier">is_completion_handler</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of <a href="../../../../../../doc/html/boost_asio/reference/CompletionHandler.html" target="_top"><span class="bold"><strong>CompletionHandler</strong></span></a>, and is callable
                  with a specified signature.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_sync_read_stream.html" title="is_sync_read_stream"><code class="computeroutput"><span class="identifier">is_sync_read_stream</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of <a href="../../../../../../doc/html/boost_asio/reference/SyncReadStream.html" target="_top"><span class="bold"><strong>SyncReadStream</strong></span></a>.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_sync_stream.html" title="is_sync_stream"><code class="computeroutput"><span class="identifier">is_sync_stream</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of both <a href="../../../../../../doc/html/boost_asio/reference/SyncReadStream.html" target="_top"><span class="bold"><strong>SyncReadStream</strong></span></a> and <a href="../../../../../../doc/html/boost_asio/reference/SyncWriteStream.html" target="_top"><span class="bold"><strong>SyncWriteStream</strong></span></a>.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <a class="link" href="../ref/boost__beast__is_sync_write_stream.html" title="is_sync_write_stream"><code class="computeroutput"><span class="identifier">is_sync_write_stream</span></code></a>
                </p>
              </td>
<td>
                <p>
                  Determine if a type meets the requirements of <a href="../../../../../../doc/html/boost_asio/reference/SyncWriteStream.html" target="_top"><span class="bold"><strong>SyncWriteStream</strong></span></a>.
                </p>
              </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
        Using the type checks with <code class="computeroutput"><span class="keyword">static_assert</span></code>
        on function or class template types will provide users with helpful error
        messages and prevent undefined behaviors. This example shows how a template
        function which writes to a synchronous stream may check its argument:
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">SyncWriteStream</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">write_string</span><span class="special">(</span><span class="identifier">SyncWriteStream</span><span class="special">&amp;</span> <span class="identifier">stream</span><span class="special">,</span> <span class="identifier">string_view</span> <span class="identifier">s</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">static_assert</span><span class="special">(</span><span class="identifier">is_sync_write_stream</span><span class="special">&lt;</span><span class="identifier">SyncWriteStream</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span>
        <span class="string">"SyncWriteStream requirements not met"</span><span class="special">);</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">write</span><span class="special">(</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">const_buffer</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">data</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">size</span><span class="special">()));</span>
<span class="special">}</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2016, 2017 Vinnie Falco<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="asio_refresher.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../using_io.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="buffer_types.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
